<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hitsoysauce.bean.User"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
	<script type="text/javascript">
		setInterval("location.reload()", 1000);
	</script>
<body>
	<h2>Java script</h2>	
	<ul>
	<%
		List<User> userList = (ArrayList<User>) request.getAttribute("userList");
		for (Iterator<User> iterator = userList.iterator(); iterator.hasNext();) {
			User item = iterator.next();
	%>
	<li> <%=item.getUsername() %>, <%=item.getPassword() %></li>
	<%
	}
	%>
	</ul>
	<hr>
	
	<h2>JSTL: foreach</h2>
	<ul>
		<c:forEach var="item" items="${userList}">
			<li><c:out value="${item.username}"/>, <c:out value="${item.password}"/></li>
		</c:forEach>
	</ul>
	
	<hr>
	
	<h2>JSTL: if  显示用户名为user1、3的用户</h2>
	<ul>
		<c:forEach var="item" items="${userList}">
			<c:if test="${item.username eq 'user1' || item.username eq 'user3'}">
				<li><c:out value="${item.username}"/>, <c:out value="${item.password}"/></li>
			</c:if>
		</c:forEach>
	</ul>
	
	<hr>
	
	<h2>JSTL: choose when  如果用户名为user1, 密码显示为p1; 如果用户名为user2, 密码显示为p2; 其余的原样输出</h2>
	<ul>
		<c:forEach var="item" items="${userList}">
			<c:choose>
				<c:when test="${item.username eq 'user1'}">
					<li><c:out value="${item.username}"/>, p1</li>
				</c:when>
				<c:when test="${item.username eq 'user2'}">
					<li><c:out value="${item.username}"/>, p2</li>
				</c:when>
				<c:otherwise>
					<li><c:out value="${item.username}"/>, <c:out value="${item.password}"/></li>
				</c:otherwise>
			</c:choose>
		</c:forEach>
	</ul>
	
	<hr>
	<h2>format date</h2>
	<h1><fmt:formatDate type="time" value="${startDate}" pattern="yyyy-MM-dd HH:mm:ss"/></h1>
</body>
</html>